package com.rykj.qxj.server.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rykj.qxj.server.dao.TaskLogMapper;
import com.rykj.qxj.server.model.entity.TaskResult;
import com.rykj.qxj.server.services.ITaskLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("taskLogService")
public class TaskLogServiceImpl implements ITaskLogService {
    @Autowired
    private TaskLogMapper taskLogMapper;

    @Override
    public PageInfo getTaskExcInfos(Integer pageNum, Integer pageSize, String taskName, String tableName) {
        PageHelper.startPage(pageNum,pageSize);
        Map<String,Object> paraMap = new HashMap<>();
        if("%".equals(taskName)){
            taskName ="\\%";
        }
        if("%".equals(tableName)){
            tableName ="\\%";
        }
        paraMap.put("taskName",taskName);
        paraMap.put("tableName",tableName);
        List<Map<String,Object>> taskLogs =  taskLogMapper.getTaskExcInfos(paraMap);
        PageInfo pageInfo = new PageInfo(taskLogs);
        return  pageInfo;
    }

    @Override
    public PageInfo getTaskExcFieldDetails(Integer pageNum, Integer pageSize, Integer taskHistoryId) {
        PageHelper.startPage(pageNum,pageSize);
        Map<String,Object> paraMap = new HashMap<>();
        paraMap.put("taskHistoryId",taskHistoryId);
        List<Map<String,Object>> taskLogDetails =  taskLogMapper.getTaskExcFieldDetails(paraMap);
        PageInfo pageInfo = new PageInfo(taskLogDetails);
        return  pageInfo;
    }

    @Override
    public Map<String, Object> getLogTaskDetails(Integer taskId) {
      return   taskLogMapper.getLogTaskDetails(taskId);
    }

    @Override
    public void saveTaskLog(List<TaskResult> taskLogs) {
        taskLogMapper.saveTaskLog(taskLogs);
    }
}
